package com.cskaoyan.service;

import com.cskaoyan.bean.PO.MarketUser;
import com.cskaoyan.bean.PO.MarketUserExample;
import com.cskaoyan.mapper.MarketUserMapper;
import com.cskaoyan.utils.MyGetCurrentTime;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * @ClassName WxAuthServiceImpl
 * @Description
 * @Author Lxz
 * @Date 2022-8-15 20:27
 */
@Service
public class WxAuthServiceImpl implements WxAuthService {
    @Autowired
    MarketUserMapper userMapper;


    @Override
    public MarketUser getUserInfo(MarketUser primaryPrincipal) {
        MarketUserExample example = new MarketUserExample();
        example.createCriteria().andUsernameEqualTo(primaryPrincipal.getUsername());
        List<MarketUser> marketUsers = userMapper.selectByExample(example);
        MarketUser marketUser = marketUsers.get(0);
        return marketUser;
    }

    @Override
    public void updateLog(MarketUser primaryPrincipal) {
        Date currentTime = MyGetCurrentTime.getCurrentTime();
        primaryPrincipal.setLastLoginTime(currentTime);
        userMapper.updateByPrimaryKeySelective(primaryPrincipal);
    }
}
